package app.game.common;

import java.util.Random;

import ryulib.game.GameControl;
import ryulib.game.GameControlGroup;
import ryulib.game.GamePlatformInfo;
import app.game.resource.ResourceAsteroid;

public class Asteroids extends GameControl {

	public Asteroids(GameControlGroup gameControlGroup) {
		super(gameControlGroup);

	}
	
	private Random _Random = new Random();
	private long _AdventInterval = 250;
	private long _AdventCount = 0;
	boolean isStart = true;
	int startCount = 0;
	
	@Override
	protected void onTick(GamePlatformInfo platformInfo) {
		long tick = platformInfo.getTick();
		
		_AdventCount = _AdventCount + tick;
		if (_AdventCount >= _AdventInterval) {
			_AdventCount = _AdventCount - _AdventInterval;
//			
//			// �ֱ������� ������ ������ �ʰ�, �����ϰ� �߻� ��Ų��.
//			if (_Random.nextInt(2) == 1) createAsteroid(platformInfo);
//			if (startCount<10){

//			}
		}
		if (isStart){
			isStart =false;
			for (int i=0; i<10; i++){
				startCount++;
				createAsteroid(platformInfo);
			}
		}

	}
	
	private void createAsteroid(GamePlatformInfo platformInfo) {
		int y = (int)((platformInfo.getCanvas().getHeight()-ResourceAsteroid.SIZE)
				*(startCount/10.0f));
		
		Asteroid asteroid = 
			new Asteroid(
					platformInfo.getCanvas().getWidth()+startCount*50, y
					
			);
		this.getGameControlGroup().addControl(asteroid);
	}
	
}
